﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace ns
{
    public class AIConfigurationReader : MonoBehaviour
    {
        public Dictionary<string, Dictionary<string, string>> Map;
        private string mainKey;
        public AIConfigurationReader(string fileName) 
        {
            Map=new Dictionary<string, Dictionary<string, string>>();
            string configFile=ConfigurationReader.GetConfigFile(fileName);
            ConfigurationReader.Reader(configFile, BulidMap);
        }

        /// <summary>
        /// 具体的构建规则
        /// </summary>
        /// <param name="line">当前行</param>
        private void BulidMap(string line)
        {
            line=line.Trim();
            if (string.IsNullOrEmpty(line)) return;
            if (line.StartsWith("["))
            {
                mainKey = line.Substring(1, line.Length - 2);
                Map.Add(mainKey, new Dictionary<string, string>());
            }
            else
            {
                string[] value = line.Split('>');
                Map[mainKey].Add(value[0], value[1]);
            }
        }
    }
}